﻿'Description:菜单定义类
'Copyright (c) : 通力凯顿（北京）系统集成有限公司
'Writer:tianFW 
'create Date:2019年1月8日
'Rewriter:
'Rewrite Date:
Imports DatabaseAccess.DBUtility
Imports BusinessRule.DTO
Imports BusinessRule.IBusiness
Imports System.Text

Public Class uLMSMenuDefinitionBusiness
    Implements IBusiness.uLMSMenuDefinitionIBusiness

    ''' <summary>
    ''' 获取定义的菜单信息
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function GetMenuDefinitionInfo() As DataTable Implements uLMSMenuDefinitionIBusiness.GetMenuDefinitionInfo
        Dim strSql As String = "SELECT mf.menudefinitionid,mf.menudefinitionname FROM menudefinition mf order by mf.menudefinitionname"
        Return DatabaseHelper.Query_ReturnDatTable(strSql)
    End Function

    ''' <summary>
    ''' 保存定义菜单信息
    ''' </summary>
    ''' <param name="dto"></param>
    ''' <param name="DMLType"> 1 添加 2 修改 3 删除</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function SaveMenuDefinition(ByVal dto As MenuDefinitionDTO, ByVal DMLType As Int32) As Boolean Implements uLMSMenuDefinitionIBusiness.SaveMenuDefinition
        SaveMenuDefinition = False
        Dim valueType As String = ""
        Dim pkValue As String = ""
        If DMLType = 1 Then
            valueType = "insert"
        ElseIf DMLType = 2 Then
            valueType = "update"
            pkValue = "MenudefinitionID"
        ElseIf DMLType = 3 Then
            valueType = "delete"
            pkValue = "MenudefinitionID"
        End If
        If Not DatabaseHelper.ExcuteDTO(dto, valueType, pkValue) Then
            Exit Function
        End If
        '如果删除，则需要删除子项
        If DMLType = 3 Then
            Dim cdto As New MenuitemDTO
            cdto.ParentID = dto.MenudefinitionID
            SaveMenuItem(cdto, 3)
        End If
        SaveMenuDefinition = True
    End Function

    ''' <summary>
    ''' 保存定义菜单项信息
    ''' </summary>
    ''' <param name="dto">实体类</param>
    ''' <param name="DMLType">1 插入 2 修改 3 删除</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function SaveMenuItem(ByVal dto As MenuitemDTO, ByVal DMLType As Int32) As Boolean Implements uLMSMenuDefinitionIBusiness.SaveMenuItem
        SaveMenuItem = False
        Dim valueType As String = ""
        Dim pkValue As String = ""
        If DMLType = 1 Then
            valueType = "insert"
        ElseIf DMLType = 2 Then
            valueType = "update"
            pkValue = "MenuitemID"
        ElseIf DMLType = 3 Then '此处按照菜单项父ID删除
            valueType = "delete"
            pkValue = "ParentID"
        End If
        If Not DatabaseHelper.ExcuteDTO(dto, valueType, pkValue) Then
            Exit Function
        End If
        SaveMenuItem = True
    End Function

    ''' <summary>
    ''' 根据菜单ID获取菜单项
    ''' </summary>
    ''' <param name="menuDefID">菜单ID</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function GetWebMenuItemsByMenuDefID(ByVal menuDefID As String) As DataTable Implements IBusiness.uLMSMenuDefinitionIBusiness.GetWebMenuItemsByMenuDefID
        Dim strsql As New StringBuilder
        strsql.AppendLine("SELECT mi.menuitemid,mi.caption,mi.description,mi.menuitemtype,mi.sequence,mi.menudefinitionid,mi.url,mi.caption")
        strsql.AppendLine("FROM menuitem mi")
        strsql.AppendFormat("WHERE mi.parentid='{0}' ORDER BY mi.sequence", menuDefID)
        Return DatabaseHelper.Query_ReturnDatTable(strsql.ToString())
    End Function
End Class
